﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections;
using System.Data;
using Bids.Core.DomainObjects;
using Bids.Data;
using Bids.Service;

namespace Bids.Web.Controllers.Admin
{
    public class LoginController : Controller
    {
        #region
        IAuthenticationService _iAuthSrv;
        public LoginController(IAuthenticationService iAuthSrv)
        {
            _iAuthSrv = iAuthSrv;
        }
        #endregion

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult dologin(string userName, string password)
        {
            Hashtable hash = new Hashtable();
            userName = userName.Trim();
            password = password.Trim();
            if (userName.Trim() == "" || password.Trim() == "")
            {
                hash["status"] = 0;
                hash["info"] = "用户名和密码不能为空";
                return Json(hash, "text/html;charset=UTF-8");
            }
            else
            {
                if (!_iAuthSrv.AdminLogin(userName, password))
                    {
                        hash["status"] = 0;
                        hash["info"] = "密码错误";
                        return Json(hash, "text/html;charset=UTF-8");
                    }
                
            }

            hash["status"] = 1;
            hash["info"] = "登录成功!跳转中...";
            return Json(hash, "text/html;charset=UTF-8");
            
        }

        public ActionResult logout()
        {
            Session.Remove("uid");
            Session.Remove("uname");
            return View("Index");
        }

    }
}
